PROPERTY:  Object::constructor


Object.constructor
 

 
A constructor property is inherited by all objects from their prototype. It is this fact that allows you to create a new instance of an object using the new operator. If you display the constructor property of any object, you see the construction of the function that created it.
 
For example, assuming the existence of an object called 'Cat', the following code would display that function:
 
Code:
document.write(Cat.constructor)
 
Output:
function Cat(breed, name, age) { this.breed = breed this.name = name
this.age = age }

 
The constructor property can also be used to compare two objects (including those, such as documents and forms, that cannot be constructed). This next example compares the 'Sheeba' object with the 'Cat' object to see if it is an instance of it:
 
Code:
if(Sheeba.constructor == Cat)
   document.write("This is an instance of 'Cat'.")


Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information